package hotLeetcode;

public class H55Leetcode {
    public boolean canJump(int[] nums) {

        int step = 1;
        int len = nums.length;
        for (int i = len - 2; i >= 0; i--) {
            if (nums[i] < step) {
                step++;
            } else {
                step = 1;
            }

        }


        return step == 1;


    }
    public static boolean canJump1(int[] nums) {

        int max = 0;
        for (int i = 0; i <= max; i++) {
            max = Math.max(max, i + nums[i]);
            if (max >= nums.length - 1) {
                return true;
            }

        }


        return false;

    }


    public static void main(String[] args) {
        int[] nums = {3, 2, 1, 0, 4};
        H55Leetcode.canJump1(nums);
    }


}
